//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Mapping Application Block
//===============================================================================

using System;
using System.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder;
using EntLibContrib.Mapping.Mappers;

namespace EntLibContrib.Mapping.Configuration
{
	/// <summary>
	/// Configuration data defining MapperData. This configuration section adds the element
	/// </summary>    
	public abstract class MapperData : MapperBaseData
	{
		#region Constants
		private const string tableNameProperty = "tableName";
		private const string mapsProperty = "maps";
		#endregion

		#region Properties
		/// <summary>
		/// The data transfer object table name to use.
		/// </summary>
		/// <value>The data transfer object table name.</value>
		[ConfigurationProperty(tableNameProperty, IsRequired = false)]
		public string TableName
		{
			get { return (string)base[tableNameProperty]; }
			set { base[tableNameProperty] = value; }
		}

		/// <summary>
		/// Gets or sets the list of maps associated with
		/// the mapper.
		/// </summary>
		/// <value>A collection of <see cref="MapData"/>.</value>
		[ConfigurationProperty(mapsProperty, IsRequired = false)]
		public NameTypeConfigurationElementCollection<MapData, CustomMapData> Maps
		{
			get
			{
				return (NameTypeConfigurationElementCollection<MapData, CustomMapData>)base[mapsProperty];
			}
		}
		#endregion

		#region Construction
		/// <summary>
		/// Initializes a new instance of the <see cref="MapperData"/> class.
		/// </summary>
		protected MapperData ()
		{
			InitializeMaps();
		}

		/// <summary>
		/// Initialize a new instance of the <see cref="MapperData"/> class.
		/// </summary>
		/// <param name="name">The name of the <see cref="MapperData"/>.</param>
		/// <param name="tableName">The data transfer object table name.</param>
		/// <param name="type">The mapper type.</param>
		protected MapperData(string name, string tableName, Type type)
			: base(name, type)
		{
			this.TableName = tableName;
			InitializeMaps();
		}
		#endregion

		#region Private Methods
		private void InitializeMaps()
		{
			base[mapsProperty] = new NameTypeConfigurationElementCollection<MapData, CustomMapData>();
		}
		#endregion
	}
}